package demo1;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;

class Saler{
    public static void main(String args[]) {
        new TestSaler();
    }
}

class TestSaler extends JFrame{
    //    JLabel lab1,lab2,lab3;
    JTextField text1,text2,text3;
    JButton button;
    JButton button1;
    JButton button2;


    public TestSaler(){
        init();
        this.setTitle("闭启炼制作简单计算器");
        this.setLocationRelativeTo(null);
        this.setLayout(new FlowLayout());
        this.setSize(500, 500);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }


    void init(){
//        lab1=new JLabel("数字1");
//        lab2=new JLabel("数字2");

        text1=new JTextField(30);
        text2=new JTextField(30);
        text3=new JTextField(45);
//        text4=new JTextField(1);


        text3.setEditable(false);
        button=new JButton("AND");
        button1=new JButton("OR");
        button2=new JButton("NOT");
        List list=new List();
        list.setSaler(this);

        List1 list1=new List1();
        list1.setSaler(this);

        List2 list2=new List2();
        list2.setSaler(this);



        button.addActionListener(list);
        button1.addActionListener(list1);
        button2.addActionListener(list2);

//        add(lab1);

        add(text1);


//        add(text4);
//        add(lab2);



        add(text2);


        add(text3);

        add(button);
        add(button1);
        add(button2);

    }
}
//********************
class List implements ActionListener{
    TestSaler saler;

    public void setSaler(TestSaler saler) {
        this.saler = saler;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
            double  num=Double.parseDouble(saler.text1.getText());
            double  price=Double.parseDouble(saler.text2.getText());
            saler.text3.setText(((int)num&(int)price)+"");
            String name="q.txt";
            File file=new File("q.txt");
//            saler.text4.setText("+");
            Font font=new Font("Times New Roman",Font.BOLD,20);
            FileWriter out= new FileWriter(name,true);

            String s=saler.text1.getText()+"AND"+saler.text2.getText()+"="+saler.text3.getText();

            out.write(s);


        }catch(NumberFormatException ex) {
            saler.text3.setText("请输入数字字符");
        } catch (FileNotFoundException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

}


class List1 implements ActionListener{
    TestSaler saler;

    public void setSaler(TestSaler saler) {
        this.saler = saler;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
            double  num=Double.parseDouble(saler.text1.getText());
            double  price=Double.parseDouble(saler.text2.getText());
            saler.text3.setText(((int)num|(int)price)+"");
            String name="q.txt";
            File file=new File("q.txt");
//            sler.text4.setText("/");


            FileWriter out= new FileWriter(name,true);

            String s=saler.text1.getText()+"OR"+saler.text2.getText()+"="+saler.text3.getText();

            out.write(s);



        }catch(NumberFormatException ex) {
            saler.text3.setText("请输入数字字符");
        } catch (FileNotFoundException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

}


class List2 implements ActionListener{
    TestSaler saler;

    public void setSaler(TestSaler saler) {
        this.saler = saler;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        // TODO Auto-generated method stub
        try {
            double  num=Double.parseDouble(saler.text1.getText());
            double  price=Double.parseDouble(saler.text2.getText());
            saler.text3.setText(~(int)num+"");
            saler.text3.setText(~(int)price+"");
            File file=new File("q.txt");

//            saler.text4.setText("+");
            Font font=new Font("Times New Roman",Font.BOLD,20);

            String name="q.txt";
            FileWriter out= new FileWriter(name,true);
//            String s="NOT"+saler.text2.getText()+"="+saler.text3.getText();
            String s="sjidh";


            out.write(s);

        }catch(NumberFormatException ex) {
            saler.text3.setText("请输入数字字符");
        } catch (FileNotFoundException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

}




public class Test {


}
